//
//  LunBoTuViewController.m
//  GXWN
//
//  Created by 要帅气的生活 on 15/11/5.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "LunBoTuViewController.h"
#import "XiangqingView.h"
#import "XiangceViewController.h"
#import "Shuomintiao.h"
#import "ShuomintiaoTwo.h"
#import "BaseView.h"
#import "ToolUtil.h"
#import "Head.h"
#import "Size.h"
#import "DiTuViewController.h"
#import "FeiYongViewController.h"
#import "MSTSViewController.h"
#import "HeZuoViewController.h"
#import "FangTaiViewController.h"
#import "XiangMuViewController.h"
#import "HuXingViewController.h"
#import "HomeViewController.h"
#import "Enshrine.h"
@interface LunBoTuViewController ()
@property (nonatomic,retain) ShuomintiaoTwo *tiaoTwo;
@property (nonatomic,retain) UIView *tishi;
@property (nonatomic,retain) UILabel *lab;
@property (nonatomic,retain) Enshrine *enshrine;
@property (nonatomic, strong) UIButton *likeButton;
@end

@implementation LunBoTuViewController

- (void)viewWillDisappear:(BOOL)animated{
    [_likeButton removeFromSuperview];
}

- (void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBar.hidden = NO;
    _likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _likeButton.frame = CGRectMake(270 * Width, -5 * Height, 50 * Height, 50 * Width);
    //    _likeButton.backgroundColor = [UIColor greenColor];
    [self.navigationController.navigationBar addSubview:_likeButton];
    [_likeButton addTarget:self action:@selector(likeButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    
    //判断是否已经收藏
    [[DataBaseHandle shareDataBaseHandle] open];
    NSArray *tempArray = [[DataBaseHandle shareDataBaseHandle] selectCollectWithcontentURL:self.enshrine.title];
    if (tempArray.count == 0) {//未收藏
        
        [_likeButton setImage:[UIImage imageNamed:@"xin1"] forState:UIControlStateNormal];
        
        _likeButton.selected = 0;
    }else{//已收藏
        [_likeButton setImage:[UIImage imageNamed:@"xin2"] forState:UIControlStateNormal];
        
        _likeButton.selected = 1;
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
//    self.navigationController.navigationBar.hidden = YES;
//    [self createTitle:@"楼盘" midTitle:@"楼盘详情"];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.hidden = NO;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(fanghui)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(shoucang)];
    self.navigationItem.title = @"楼盘详情";
    
    
    self.xiangqing = [[XiangqingView alloc] initWithFrame:CGRectMake(0, 64, WindowWidth, 0.36*WindowHeight)];
    [self.view addSubview:self.xiangqing];
    self.xiangqing.img.image = [UIImage imageNamed:self.str];
    [self.xiangqing addTarget:self selector:@selector(xiangce)];
    
    self.tiao = [[Shuomintiao alloc] initWithFrame:CGRectMake(0, 304*Height, WindowWidth, 105*Height)];
   // tiao.backgroundColor = [UIColor grayColor];

    [self.view addSubview:self.tiao];
    [self.tiao.view addTarget:self selector:@selector(ditu)];
    [ToolUtil createLine:409 superView:self.view lift:10 width:WindowWidth - 20 hight:0.5 color:[UIColor cyanColor]];

    [self.view addSubview:self.tiao];
    [self.tiao.view addTarget:self selector:@selector(ditu)];
    [ToolUtil createLine:409 superView:self.view lift:10 width:WindowWidth - 20 hight:0.5 color:[UIColor grayColor]];

    
    self.tiaoTwo = [[ShuomintiaoTwo alloc] initWithFrame:CGRectMake(0, 410*Height, WindowWidth, 120*Height)];
   // self.tiaoTwo.backgroundColor = [UIColor grayColor];
    [self.view addSubview:self.tiaoTwo];
    [self.tiaoTwo.view addTarget:self selector:@selector(dianhua)];
    self.tiaoTwo.name.text = @"林辰 -";
    self.tiaoTwo.label32.text = @"17767092620";
    
    [ToolUtil createLine:531*Height superView:self.view lift:10 width:WindowWidth - 20 hight:0.5 color:[UIColor cyanColor]];
    
    [self TheTail];
    self.enshrine = [[Enshrine alloc] init];
    self.enshrine.picture = self.str;
    self.enshrine.title = @"安静好景";
    self.enshrine.address = @"中国.上海";
}
-(void)fanghui{
    [self.navigationController popViewControllerAnimated:YES];
   
//    self.navigationController.navigationBarHidden = YES;
    self.tabBarController.tabBar.hidden = NO;
}
-(void)shoucang{
    NSLog(@"收藏");
    MFJNight *njght = [MFJNight defaultNight];
    if (njght.nightKey) {
        NSLog(@"登入状态");
    }else{
//        if (self.tishi == nil) {
//            self.tishi = [[UIView alloc] init];
//            self.tishi.frame = CGRectMake(0, 0, 375/2, 30);
//            self.tishi.center = self.view.center;
//            [self.view addSubview:self.tishi];
//            self.lab = [[UILabel alloc] initWithFrame:CGRectMake(20, 4, 375/2-40, 22)];
//            [self.tishi addSubview:self.lab];
//            self.lab.text = @"您还未登入,请先登入";
//            self.lab.textColor = [UIColor whiteColor];
//            self.lab.textAlignment = 1;
//            self.lab.font = [UIFont systemFontOfSize:15];
//            self.tishi.backgroundColor = [UIColor blackColor];
//            self.tishi.alpha = 0.5;
//            self.tishi.layer.cornerRadius = 13;
//        }else{
//            self.tishi.frame = CGRectMake(0, 0, 375/2, 30);
//            self.tishi.center = self.view.center;
//            [self.view addSubview:self.tishi];
//            self.lab.frame = CGRectMake(20, 4, 375/2-40, 22);
//            [self.tishi addSubview:self.lab];
//            self.lab.text = @"您还未登入,请先登入";
//            self.lab.textColor = [UIColor whiteColor];
//            self.lab.textAlignment = 1;
//            self.lab.font = [UIFont systemFontOfSize:15];
//            self.tishi.backgroundColor = [UIColor blackColor];
//            self.tishi.alpha = 0.5;
//            self.tishi.layer.cornerRadius = 13;
//        }
//        [UIView animateWithDuration:1.5 animations:^{
//            self.tishi.alpha = 0.6;
//            
//        } completion:^(BOOL finished) {
//            [self.tishi removeFromSuperview];
//        }];
        
//        NSLog(@"%@",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]);
//        [DataBaseHandle shareDataBaseHandle];
//        [[DataBaseHandle shareDataBaseHandle] open];
//        [[DataBaseHandle shareDataBaseHandle] createTable];
//        [[DataBaseHandle shareDataBaseHandle]insertCollect:self.enshrine];
//        [[DataBaseHandle shareDataBaseHandle] close];
        [self prompt:@"请先登录"];
    }
}
-(void)xiangce{
    NSLog(@"相册");
    XiangceViewController *xiangce = [[XiangceViewController alloc] init];
    [self presentViewController:xiangce animated:YES completion:^{
        
    }];
}
-(void)TheTail{
    
    NSArray *arr = @[@"购房费用",@"房态",@"项目详情",@"合作规则",@"主力户型"];
    for (int i = 0; i < 5; i++) {
        BaseView *button = [[BaseView alloc] initWithFrame:CGRectMake((25+65*i)*Width, 540*Height, 65, 70)];
        [self.view addSubview:button];
        button.tag = 70+i;
        //button.backgroundColor = [UIColor redColor];
        [button addTarget:self selector:@selector(weibu:)];
        
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(12, 7, 41, 30)];
        img.image = [UIImage imageNamed:[NSString stringWithFormat:@"weibu%d.png",i]];
        [button addSubview:img];
        
        UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(5, 45, 55, 25)];
        name.textAlignment = 1;
        name.text = arr[i];
        name.font = [UIFont boldSystemFontOfSize:13];
        [button addSubview:name];
    }
    
    UIButton *tuisong = [[UIButton alloc] initWithFrame:CGRectMake(50*Width, 622*Height, 275, 35)];
    tuisong.layer.cornerRadius = 5;
    [self.view addSubview:tuisong];
    tuisong.backgroundColor = [UIColor greenColor];
    [tuisong setTitle:@"马上推送" forState:UIControlStateNormal];
    tuisong.titleLabel.textAlignment = 1;
    [tuisong addTarget:self action:@selector(tuisong) forControlEvents:UIControlEventTouchUpInside];
}

-(void)ditu{
    NSLog(@"地图");
    DiTuViewController *ditu = [[DiTuViewController alloc] init];
    [self.navigationController pushViewController:ditu animated:YES];
    ditu.view.backgroundColor = [UIColor whiteColor];
}
-(void)dianhua{
    NSLog(@"电话");
    [ToolUtil callPhone:self phone:self.tiaoTwo.label32.text];
}
-(void)weibu:(BaseView *)button
{

    if (button.tag == 70) {
        [self jump:nil to:[[FeiYongViewController alloc] init]];
    }else if (button.tag == 71){
        [self jump:nil to:[[FangTaiViewController alloc] init]];
    }else if (button.tag == 72){
        [self jump:nil to:[[XiangMuViewController alloc] init]];
    }else if (button.tag == 73){
        [self jump:nil to:[[HeZuoViewController alloc] init]];
    }else if (button.tag == 74){
        [self jump:nil to:[[HuXingViewController alloc] init]];
    }
    
    NSLog(@"%ld",button.tag);
}
-(void)tuisong{
    NSLog(@"马上推送");
}
-(void)likeButtonClicked{
    NSLog(@"❤️");
}
@end
